package fr.umlv.m2.jee.birt.service.comment.impl;

import java.util.ArrayList;
import java.util.List;

import fr.umlv.m2.jee.birt.service.comment.DisplayComment;
import fr.umlv.m2.jee.birt.service.comment.IDisplayCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import fr.bdf.center.birt.persistence.comment.Comment;
import fr.bdf.center.birt.persistence.comment.ICommentDAO;

@Service("displayCommentService")
public class DefaultDisplayCommentService implements IDisplayCommentService {

    @Autowired
    private ICommentDAO commentDAO;

    @Override
    @Transactional(readOnly=true)
    public List<DisplayComment> getAllDisplayComment() {
        List< Comment > comments = commentDAO.findAll();
        ArrayList< DisplayComment > returned = new ArrayList< DisplayComment >(comments.size());

        for (Comment comment : comments) {
            returned.add(new DisplayComment(comment));
        }
        return returned;
    }

    @Override
    @Transactional(readOnly=true)
    public DisplayComment getDisplayCommentAccordingBusinessId(String businessId) {
        Comment comment = commentDAO.findByBusinessId(businessId);

        return new DisplayComment(comment);
    }

}
